﻿using System;
using System.Windows.Forms;

namespace DisplayDemo
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnValid_Click(object sender, EventArgs e)
        {
            string guid = txtValue.Text.Trim();
            if (guid.Length != 36)
            {
                MessageBox.Show("授权码无效。", "提示");
                return;
            }

            switch (new Manager().Register(guid))
            {
                case -1:
                    MessageBox.Show("授权码无效。","提示"); 
                    break;
                case 0:
                    MessageBox.Show("注册失败。","提示"); 
                    break;
                case 1:
                    MessageBox.Show("授权成功!\n\n感谢您对快开彩网的支持!\n\n请重新启动程序!", "感谢");
                    Application.Exit();
                    break;
                default:
                    MessageBox.Show("注册失败，请检查网络连接是否正常!", "提示"); 
                    break;
            }
        }

        private void btnTry_Click(object sender, EventArgs e)
        {
            string resp = new WebUtils().DoGet("http://passport.kkcai.net/key.aspx?key=" + HardwareHelper.GetKey());

            if (String.IsNullOrEmpty(resp))
            {
                MessageBox.Show("试用失败。请检查网络连接是否正常。", "提示");
            }
            else
            {
                if (resp != "true")
                {
                    MessageBox.Show("暂停试用。请正式购买。\n\n" + resp, "提示");
                }
                else
                {
                    this.Close();
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("https://me.alipay.com/kkcai");
            }
            catch { }
        }
    }
}
